package com.graduate.cec.initException;


import com.alibaba.fastjson.JSON;
import com.graduate.cec.common.JsonResult;
import com.graduate.cec.common.ResponseCode;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 权限表不足
 */
public class SimpleAccessDeniedHandler implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException e) throws IOException, ServletException {
        JsonResult jsonResult = JsonResult.failed(ResponseCode.ERR_PERMISSIONS,"对不起,您没有权限");
        response.setContentType("application/json;charset=utf-8");
        response.getWriter().write(JSON.toJSONString(jsonResult));
        response.flushBuffer();
    }
}
